# -*- coding: UTF-8 -*-
from django.forms import ModelForm
from .models import Game
from django import forms
from myauth.models import PlatForm
from cmdb.models import Server
from django.forms import extras,widgets
from datetimewidget.widgets import DateTimeWidget, DateWidget, TimeWidget

#定义Node的Form,Form名字为 模式名+Form
class GameForm(ModelForm):
    # open_date=forms.DateTimeField(widget=DateTimeWidget(usel10n=True, bootstrap_version=3))
    #自定义验证游戏账户名
    def clean_game_user(self):
        game_user = self.cleaned_data['game_user']
        if 'game_user' in self.changed_data:

            user=Game.objects.filter(game_user=game_user) or None
            if user:
                raise forms.ValidationError('游戏用户名%s已经存在' %game_user)
        return game_user


    #自定义ModelForm的内容
    class Meta:
        #该ModelForm参照Model: Node
        model = Game
        #在Form中不显示node_signer这个字段
        # exclude = ['node_signer']
        #fields=['id','ip','ip_extra']
        exclude=['create_date','update_date']

class Game_Search_Form(forms.Form):
    STATUS_CHOICE = (
        (-1, '未安装'),
        (0, '已经安装'),
        (1, '安装中'),
        (2, '已经合服'),
        (3, '特殊状态'),
    )

    GAME_TYPE_CHOICES = (
        ('s', '正式服'),
        ('t', '测试服'),
        ('d', '开发服'),
    )

    name=forms.CharField(label='游戏名:',required=False)
    version=forms.CharField(label='版本号:',required=False)
    #server=forms.ModelChoiceField(label='服务端代码存放:',queryset=Server.objects.all(),to_field_name='id',required=False)
    platform=forms.ModelChoiceField(
                label='平台:',queryset=PlatForm.objects.all(),to_field_name='id',required=False)
    state = forms.ChoiceField(label='安装状态', choices=STATUS_CHOICE,required=False)
    game_type = forms.ChoiceField(label='游戏类型', choices=GAME_TYPE_CHOICES,required=False)


class Test_Game_Search_Form(forms.Form):
    STATUS_CHOICE = (
        (-1, '未安装'),
        (0, '已经安装'),
        (1, '安装中'),
        (2, '已经合服'),
        (3, '特殊状态'),
    )

    GAME_TYPE_CHOICES = (
        ('t', '测试服'),
        ('d', '开发服'),
    )

    name=forms.CharField(label='游戏名:',required=False)
    version=forms.CharField(label='版本号:',required=False)
    #server=forms.ModelChoiceField(label='服务端代码存放:',queryset=Server.objects.all(),to_field_name='id',required=False)
    platform=forms.ModelChoiceField(
                label='平台:',queryset=PlatForm.objects.all(),to_field_name='id',required=False)
    state = forms.ChoiceField(label='安装状态', choices=STATUS_CHOICE,required=False)
    game_type = forms.ChoiceField(label='游戏类型', choices=GAME_TYPE_CHOICES,required=False)
